package service

import (
	"errors"
	"github.com/go-admin-team/go-admin-core/sdk/service"
	"gorm.io/gorm"
	"tuowei.com/app/api/models"
	"tuowei.com/pkg/xlog"
)

type ApiCourseGift struct {
	service.Service
}

func (e ApiCourseGift) Get(courseId []int, data *[]models.SysCourseGift) error {
	var model models.SysCourseGift

	err := e.Orm.Model(&model).Debug().
		Where("course_id in ?", courseId).
		Find(&data).Error

	if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
		err = errors.New("查看对象不存在或无权查看")
		xlog.Errorf("db error: %s", err)
		return err
	}

	return nil
}
